<template>
  <!-- 设置佣默认金比例 -->
  <el-dialog
    :visible.sync="popVisible"
    :close-on-click-modal="false"
    :show-close="false"
    top="30vh"
    width="450px"
  >
    <span slot="title" class="d-flex ai-baseline">
      <span class="fs-xl" style="margin-left: 8px">设置默认佣金</span>
      <!-- <span>（注：输入小区或关键字后，需点击“搜索”按钮）</span> -->
    </span>
    <el-form :model="houDelVO" label-width="110px" size="mini">
      <el-form-item
        :label="configItem.title"
        :prop="configItem.key"
        :rules="[
          {
            required: configItem.required,
            message: '不能为空',
            trigger: 'blur',
          },
          ...(configItem.rules || []),
        ]"
      >
        <el-input
          v-model="houDelVO.commissionRate"
          :style="{ width: configItem.width }"
        >
          <i v-if="configItem.unit" slot="suffix" style="font-style: normal">{{
            configItem.unit
          }}</i>
        </el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button plain @click="handleClose">取消</el-button>
      <el-button type="primary" @click="handlePopConfirm">确认</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { savePersonalDefaultInfo, getPersonalDefaultInfo } from "@/api/user";
export default {
  props: {
    popVisible: {
      type: Boolean,
      default: false,
    },
    configItem: {
      type: Object,
      default() {
        return {};
      }
    },
  },
  data() {
    return {
      houDelVO: {
        commissionRate: "",
      },
    };
  },
  watch: {
    popVisible: {
      handler(val) {
        if (val) {
          getPersonalDefaultInfo({
            tag: "佣金比例",
            page: 1,
            pageSize: 10,
          }).then(({ isSuccess, content }) => {
            if (!isSuccess) return;
            if (content && content.rows && content.rows.length) {
              this.houDelVO.commissionRate = content.rows[0].commissionRate;
            }
          });
        }
      },

      immediate: true,
    },
  },
  mounted() {
  },
  methods: {
    handleClose() {
      this.$emit("update:popVisible", false);
    },
    handlePopConfirm() {
      let bool = this.configItem.checkValue(this.houDelVO.commissionRate);
      if (!bool) {
        return this.$message.error("填写不合格！");
      }

      savePersonalDefaultInfo({
        tag: "佣金比例",
        commissionRate: Number(this.houDelVO.commissionRate),
      }).then(({ isSuccess }) => {
        if (isSuccess) {
          this.handleClose();
          this.$emit("onsetdefaultvalue", this.houDelVO.commissionRate);

          this.$message.success("设置成功！");
        }
      });
    },
  },
};
</script>

<style>
</style>